Vue.component('update', {
    template: `
		<el-dialog title="修改代币" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="自定义币种名称" prop="name">
							<el-input  v-model="form.name" autoComplete="off" clearable  placeholder="请输入自定义币种名称"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="币种名称" prop="currency_name">
							<el-input  v-model="form.currency_name" autoComplete="off" clearable  placeholder="请输入自定义币种名称"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="币种合约地址" prop="tokentx">
							<el-input  v-model="form.tokentx" autoComplete="off" clearable  placeholder="请输入币种合约地址"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="价格对比货币" prop="price_currency">
							<el-input  v-model="form.price_currency" autoComplete="off" clearable  placeholder="请输入价格对比货币"></el-input>
							<small style="color: rgb(192, 196, 204);">例如：USDT、USD、BNB、BTC  (仅支持链上常规币种名称)</small>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="币种当前价格" prop="current_price">
							<el-input  v-model="form.current_price" autoComplete="off" clearable  placeholder="请输入当前价格"></el-input>
							<small style="color: rgb(192, 196, 204);">自动更新链上对比价格 (自定义除外)</small>
						</el-form-item>
					</el-col>
				</el-row>
                <el-row >
					<el-col :span="24">
						<el-form-item label="币种所属:">
                            <el-radio-group v-model="form.type">
								<el-radio :label="1">BEP20(币安)</el-radio>
								<el-radio :label="2">TRC20(波场)</el-radio>
								<el-radio :label="99">未上链(自定义)</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="兑换功能:">
                            <el-radio-group v-model="form.exchange">
								<el-radio :label="1">开启</el-radio>
								<el-radio :label="2">关闭</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="手续费类型:">
                            <el-radio-group v-model="form.ec_type">
                                <el-radio :label="0">不收取</el-radio>
								<el-radio :label="1">固定收取</el-radio>
								<el-radio :label="2">百分比收取</el-radio>
							</el-radio-group>
							<small style="color: rgb(192, 196, 204);">兑换</small>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="兑换手续费" prop="ec">
							<el-input  v-model="form.ec" autoComplete="off" clearable  placeholder="请输入费用"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="划转功能:">
                            <el-radio-group v-model="form.transfer">
								<el-radio :label="1">开启</el-radio>
								<el-radio :label="2">关闭</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="手续费类型:">
                            <el-radio-group v-model="form.tc_type">
                                <el-radio :label="0">不收取</el-radio>
								<el-radio :label="1">固定收取</el-radio>
								<el-radio :label="2">百分比收取</el-radio>
							</el-radio-group>
							<small style="color: rgb(192, 196, 204);">划转</small>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="划转手续费" prop="tc">
							<el-input  v-model="form.tc" autoComplete="off" clearable  placeholder="请输入费用"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="币种状态:">
                            <el-radio-group v-model="form.status">
								<el-radio :label="1">开启</el-radio>
								<el-radio :label="2">关闭</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="币种使用对象:">
                            <el-radio-group v-model="form.business">
								<el-radio :label="1">用户直接使用</el-radio>
								<el-radio :label="2">非用户直接使用</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`,
    components:{
    },
    props: {
        show: {
            type: Boolean,
            default: false
        },
        size: {
            type: String,
            default: 'small'
        },
        info: {
            type: Object,
        },
    },
    data(){
        return {
            form: {
                name:'',
                currency_name:'',
                tokentx:'',
                price_currency:'',
                type:99,
                today_price:'',
                pcurrent_pricerize:'',
                status:'',
                business:'',
                exchange:2,
                transfer:2,
                current_price:0,
                ec_type:0,
                ec:0,
                tc_type:0,
                tc:0,
            },
            loading:false,
            rules: {
                name:[
                    {required: true, message: '自定义币种名称不能为空', trigger: 'blur'},
                ],
                currency_name:[
                    {required: true, message: '币种名称不能为空', trigger: 'blur'},
                ],
            }
        }
    },
    watch:{

    },
    methods: {
        open(){
            this.form = this.info
        },
        submit(){
            this.$refs['form'].validate(valid => {
                if(valid) {
                    this.loading = true
                    axios.post(base_url + '/Currency/edit',this.form).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.$emit('refesh_list')
                            this.closeForm()
                        }else{
                            this.loading = false
                            this.$message.error(res.data.msg)
                        }
                    }).catch(()=>{
                        this.loading = false
                    })
                }
            })
        },
        closeForm(){
            this.$emit('update:show', false)
            this.loading = false
            if (this.$refs['form']!==undefined) {
                this.$refs['form'].resetFields()
            }
        },
    }
})
